//
// Created by Administrator on 2025/8/22.
//


#include "StrBlob.h"
#include "StrBlobPtr.hpp"
std::ostream &operator<<(std::ostream &os, const StrBlob &b1) {
    if (b1.size() == 0) {
        return os;
    }
    os << b1.front();
    for (StrBlob::size_type i = 1; i < b1.size(); ++i) {
        os << std::string(" ") << b1[i];  // 假设 StrBlob 有 operator[] 或者 at()
    }
    return os;
}


const std::string& StrBlob::operator[](size_type i) const{
    check(i, "StrBlob::operator[] out of StrBlob vector range");
    return data->at(i);
}


std::string& StrBlob::operator[](size_type i) {
    check(i, "StrBlob::operator[] out of StrBlob vector range");
    return data->at(i);
}
StrBlob::StrBlob() : data(std::make_shared<std::vector<std::string>>())
{

}

StrBlob::StrBlob(std::initializer_list<std::string> il) :
    data(make_shared<std::vector<std::string>>(il))
{
}


void StrBlob::check(size_type i, const std::string& msg) const
{
    if (i >= data->size())
        throw std::out_of_range(msg);
}

std::string& StrBlob::front()
{
    check(0, "front on empty StrBlob");
    return data->front();
}

const std::string& StrBlob::front() const
{
    check(0, "front on empty StrBlob");
    return data->front();
}

std::string& StrBlob::back()
{
    check(0, "back on empty StrBlob");
    return data->back();
}

const std::string& StrBlob::back() const
{
    check(0, "back on empty StrBlob");
    return data->back();
}

void StrBlob::pop_back()
{
    check(0, "pop_back on empty StrBlob");
    data->pop_back();
}

StrBlobPtr StrBlob::begin(){
    return StrBlobPtr(*this);
}

StrBlobPtr StrBlob::end(){
    return StrBlobPtr(*this, data->size());
}